using System;
using System.Collections.Generic;
using System.Linq;
using VCards.Types;

namespace VCards.Lookups;

public static class EmailTypeLookup
{
    private static readonly Dictionary<EmailType, string> Lookup = new()
    {
        {EmailType.AmericaOnline, "AOL"},
        {EmailType.AppleLink, "AppleLink"},
        {EmailType.ATTMail, "ATTMail"},
        {EmailType.CompuServeInformationServices, "CIS"},
        {EmailType.EWorld, "eWorld"},
        {EmailType.Smtp, "INTERNET"},
        {EmailType.IBMMail, "IBMMail"},
        {EmailType.MCIMail, "MCIMail"},
        {EmailType.PowerShare, "POWERSHARE"},
        {EmailType.Prodigy, "PRODIGY"},
        {EmailType.Telex, "TLX"},
        {EmailType.X400, "X400"}
    };

    public static string ToVCardString(this EmailType type)
    {
        return Lookup[type];
    }

    public static string ToVCardString(this EmailType? type)
    {
        if (type == null)
        {
            return string.Empty;
        }

        return Lookup[type.Value];
    }

    public static EmailType Parse(string type)
    {
        if (string.IsNullOrWhiteSpace(type))
        {
            return EmailType.Smtp;
        }

        return Lookup.FirstOrDefault(x => string.Equals(x.Value, type, StringComparison.OrdinalIgnoreCase)).Key;
    }
}